package com.xiaowu.bot.repository;


import com.xiaowu.bot.entity.ChatInfo;
import org.springframework.stereotype.Repository;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Repository
public class MemoryChatHistoryRepository implements ChatHistoryRepository {

    private Map<String, String> chatInfos = new LinkedHashMap<>();

    @Override
    public List<ChatInfo> getChats() {
        return chatInfos.entrySet().stream()
                .map(entry -> new ChatInfo(entry.getKey(), entry.getValue()))
                .collect(Collectors.toList());
    }

    @Override
    public void save(String chatId, String prompt) {
        chatInfos.put(chatId, prompt);
    }

    @Override
    public void clearByChatId(String chatId) {
        chatInfos.remove(chatId);
    }
}
